package com.huilian.iotbox.admin.wap.service.impl;

import com.huilian.iotbox.admin.wap.dao.BrandInfoDao;
import com.huilian.iotbox.admin.wap.service.BrandInfoService;
import com.huilian.iotbox.data.dto.BrandInfoDto;
import com.huilian.iotbox.data.vo.BrandInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

/**
 * @author 龙 路 飞
 * @CreateDate: 2021-11-09 16:38
 * @Description:
 */
@Service
public class BrandInfoServiceImpl implements BrandInfoService {
    @Autowired
    private BrandInfoDao brandInfoDao;

    @Override
    public BrandInfoVo findByUserId(Integer userId) {
        BrandInfoVo brandInfoVo = brandInfoDao.findByUserId(userId);
        if (ObjectUtils.isEmpty(brandInfoVo)) {
            BrandInfoDto brandInfoDto = new BrandInfoDto();
            brandInfoDto.setUserId(userId);
            Integer result = brandInfoDao.insert(brandInfoDto);
            if (result > 0) {
                brandInfoVo = brandInfoDao.findByUserId(userId);
            }
        }
        return brandInfoVo;
    }
}
